﻿var iHeight = 0;
var iTop = 0;
var clientHeight = 0;
var iIntervalId = null;
var itemsSize = 0;
var isHave = 0;
var s_pageNo = 0;   // 当前页数，默认设为第 1 页

// 添加定时检测事件，每1秒检测一次  
iIntervalId = setInterval("_onScroll();", 1000);

// 取得当前页面显示所占用的高度  
function getPageHeight() {
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    }
    iHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

// 判断滚动条是否到达底部  
function reachBottom() {
    var scrollTop = 0;
//    if (document.documentElement && document.documentElement.scrollTop) {
//        scrollTop = document.documentElement.scrollTop;
//    } else if (document.body) {
//        scrollTop = document.body.scrollTop;
    //    }
    scrollTop = $("#dvScroll").scrollTop();

    if ((scrollTop > 0) && (scrollTop + $("#dvScroll").height() >= $("#dvShow") * 0.99)) {
        return true;
    } else {
        return false;
    }
}

// 检测事件，检测滚动条是否接近或到达页面的底部区域，0.99是为了更接近底部时
function _onScroll() {
    iTop = document.documentElement.scrollTop + document.body.scrollTop;
    getPageHeight();
    if (reachBottom()) {
        var $strParams = strList("beginTime", $("#IptBeginDt").val()) + "|" + strList("endTime", $("#IptEndDt").val());
        if (s_pageNo == 0) {
            DataBind("SaleProductReport.aspx", 1, $strParams, "dvWait", "为您加载数据中，请稍候......", "dvHeader", "dvShow", "dvWaitMore", "50", s_pageNo);
            s_pageNo = s_pageNo + 1;
        }
        else {
            DataBind("SaleProductReport.aspx", 0, $strParams, "dvWait", "为您加载数据中，请稍候......", "dvHeader", "dvShow", "dvWaitMore", "50", s_pageNo);
            s_pageNo = s_pageNo + 1;
        }

    }
}

$(document).ready(function () {
    $("#btnLoad").click(function () {
        s_pageNo = 0;
        var $strParams = strList("beginTime", $("#dtpBeginTime").val()) + "|" + strList("endTime", $("#dtpEndTime").val());
        DataBind("SaleProductReport.aspx", 1, $strParams, "dvWait", "为您加载数据中，请稍候......", "dvHeader", "dvShow", "dvWaitMore", "50", s_pageNo);
        s_pageNo = s_pageNo + 1;
        $("#dvScroll").height(document.body.clientHeight - 400);
        $("#dvShow").width(document.body.clientWidth + 500);
    });
});

